package com.isunland.managesystem.ui;

import com.google.gson.Gson;
import com.isunland.managesystem.base.Base;
import com.isunland.managesystem.base.BaseNetworkDialogFragment;
import com.isunland.managesystem.common.ApiConst;
import com.isunland.managesystem.entity.CustomerDialog;
import com.isunland.managesystem.entity.EventCategory;
import com.isunland.managesystem.entity.EventCategoryOriginal;
import com.isunland.managesystem.utils.ToastUtil;
import java.util.ArrayList;

/**
 * 对象功能:
 * 开发公司: 北京信普达系统工程有限公司
 * 开发人员: HuXiaoDan
 * 创建时间: 2017/4/20 16:09
 */
public class EventCategoryDialogFragment extends BaseNetworkDialogFragment {
  @Override public ArrayList<CustomerDialog> resolveResponse(String arg0) {
    ArrayList<CustomerDialog> mlist = new ArrayList<>();
    ArrayList<EventCategory> rows = new ArrayList<>();
    EventCategoryOriginal original = new Gson().fromJson(arg0, EventCategoryOriginal.class);
    if (Base.SUCCESS == original.getResult() && original.getRows() != null) {
      rows.clear();
      rows.addAll(original.getRows());
    } else {
      ToastUtil.show(original.getMessage());
    }

    for (EventCategory category : rows) {
      mlist.add(new CustomerDialog(category.getRecordText(), category.getRecordCode()));
    }
    return mlist;
  }

  @Override public String getUrl() {
    return ApiConst.URL_EVENTS_CATEGORY;
  }
}
